<?php
declare(strict_types=1);
namespace Dao;
// hook dao_sys_menu_use.php

use Field\SysMenuConst;
use Model\SysMenuModel;

class SysMenuDao extends SysMenuModel
{
	// hook dao_sys_menu_public_start.php

	protected array $add_rule	=	[];
    protected array $edit_rule	=	[];

    protected array $rule	=	[
		/*
		"mobile"=>[
			"max"=>3
			"min"=>3
			"func"=>'isMobile'
			"error"=>false,
			'message'=>'格式有误'
		],
		"username"=>[
			"max"=>3
			"min"=>3
			"func"=>'checkS'
			"error"=>false,
			'message'=>'格式有误'
		],
		*/
	];
	//数据，字段，验证规则
	/*
	function isMobile($data,$field,$val){
	
		return true;
	}
	*/
	
	// hook dao_sys_menu_public_end.php

    public function CacheMenu()
    {
        $data = $this->CacheGet('SysMenu');
        if(empty($data[0])){
            $data = $this->select([SysMenuConst::TypeId => 'menu']);
            $this->CacheSet('SysMenu',$data);
        }
        return $data;
    }
    public function CacheApiOption()
    {
        $data = $this->CacheGet('ApiOption');
        if(empty($data[0])){
            $data = $this->select([SysMenuConst::Node =>['LLIKE'=>'/option']]);
            $this->CacheSet('ApiOption',$data);
        }
        return $data;
    }

    public function CacheApiIndex()
    {
        $data = $this->CacheGet('ApiIndex');
        if(empty($data[0])){
            $data = $this->select([SysMenuConst::Method =>"PUT"]);
            $this->CacheSet('ApiIndex',$data);
        }
        return $data;
    }

    public function update(array $cond, array $new): bool|int
    {
        $this->CacheDel('SysMenu');
        $this->CacheDel('ApiOption');
        return parent::update($cond, $new); // TODO: Change the autogenerated stub
    }

    public function updateByIndex(array $cond_array, array $new): bool|int
    {
        $this->CacheDel('SysMenu');
        $this->CacheDel('ApiOption');
        return parent::updateByIndex($cond_array, $new); // TODO: Change the autogenerated stub
    }

    public function delete(array $cond): bool|int
    {
        $this->CacheDel('SysMenu');
        $this->CacheDel('ApiOption');
        return parent::delete($cond); // TODO: Change the autogenerated stub
    }


    public function deleteByIndex(array $cond_array): bool|int
    {
        $this->CacheDel('SysMenu');
        $this->CacheDel('ApiOption');
        return parent::deleteByIndex($cond_array); // TODO: Change the autogenerated stub
    }

    // hook dao_sys_menu_end.php
}
?>